//Regressions using quarterly data 2004-2018 but with 4-quarter growth

clear all
set more off
qui use GU04_18_Q4_j_all, replace
qui tsset idj yrq2, quarterly 

drop ft_*  union_* own_* inc_* profit_*
keep if j_ft==int(j_ft)
qui tab j_ft, gen(ft_)
keep if j_union==int(j_union)
qui tab j_union, gen(union_)
keep if j_ownership==int(j_ownership)
qui tab j_ownership, gen(own_)
keep if j_inc==int(j_inc)
qui tab j_inc, gen(inc_)
keep if j_profit==int(j_profit)
qui tab j_profit, gen(profit_)

drop gdpsize_* gdpfemog_* gdpn1_* gdprg_* gdpft_* gdp gdpunion_* gdpown_* gdpinc_* gdpprofit_* 
foreach a of varlist size_* femog_* n1_* rg_* ft_*  union_* own_* {
qui gen gdp`a'=`a'*logrgdpdiff
}

drop if missing(logdiffj_ahr) | missing(logdiffj_cqtotben) | missing(logdiffj_comp)

qui tsset idj yrq2, quarterly 
sort idj cycle
qui egen wtcon=mean(j_estoccwt), by (idj)

qui gen dp7=0
qui replace dp7=1 if year>2007
foreach a of varlist logrgdpdiff {
qui gen dp7`a'=`a'*dp7
}

//============================================================================

//Table 3
foreach a of varlist j_ahr j_cqtotben j_comp { 
eststo: capture noisily areg logdiff`a' logrgdpdiff cycle dp7logrgdpdiff dp7 inc_* profit_* j_ivf_total_points l4.logemplydiff size_* ft_* femog_* n1_* rg_*  union_* own_* [pw=j_estoccwt], absorb(idj) vce(cluster n2)  
eststo: capture noisily xtregar logdiff`a' logrgdpdiff cycle dp7logrgdpdiff dp7 inc_* profit_* j_ivf_total_points l4.logemplydiff size_* ft_* femog_* n1_* rg_*  union_* own_* [aw=wtcon], fe rhotype(regress)  
esttab, se ar2 stats(N r2)
estimates clear
}
